/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 * Date: 2024-04-24
 * Time: 13:42
 */

import java.io.*;
import java.util.Scanner;

/**
 * 把一个文件的内容复制到另一个文件
 */
public class Demo2 {
    public static void main(String[] args) throws FileNotFoundException {
        System.out.println("请输入源文件路径");
        Scanner scanner = new Scanner(System.in);
        String rootPath = scanner.next();
        System.out.println("请输入目标路径");
        String desPath = scanner.next();
        File rootFile = new File(rootPath);
        if(!rootFile.isFile()){
            System.out.println("源文件路径错误");
            return;
        }

        File desFile = new File(desPath);
        if(!desFile.getParentFile().isDirectory()){
            return;
        }
       try(InputStream inputStream = new FileInputStream(rootFile);
           OutputStream outputStream = new FileOutputStream(desFile)){
           while(true){
               byte[] bytes = new byte[1024];
             int n =  inputStream.read(bytes);
               if(n==-1){
                   break;
               }
               outputStream.write(bytes,0,n);

           }

       } catch (IOException e) {
           e.printStackTrace();
       }
    }
}
